﻿using System;
using System.Data;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using WeFrame.Core;
using WeFrame.Core.Common;

namespace WeFrame.Web.Admin.SystemAdmin
{
    public partial class ChangePassword :  WeFrame.Core.UI.AdminPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                WeFrame.Core.Model.SystemAdminEntity model = this.GetSystemAdmin();
                ShowInfo(model.Id);
            }
        }

        #region 赋值操作=================================
        private void ShowInfo(int _id)
        {
            WeFrame.Core.BLL.SystemAdminBLL bll = new WeFrame.Core.BLL.SystemAdminBLL();
            WeFrame.Core.Model.SystemAdminEntity model = bll.GetModel(_id);
            txtUserName.Text = model.UserName;
            txtRealName.Text = model.RealName;
            txtTelephone.Text = model.Telephone;
            txtEmail.Text = model.Email;
        }
        #endregion

        //保存
        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            WeFrame.Core.BLL.SystemAdminBLL bll = new WeFrame.Core.BLL.SystemAdminBLL();
            WeFrame.Core.Model.SystemAdminEntity model =this.GetSystemAdmin();

            if (DESEncrypt.Encrypt(txtOldPassword.Text.Trim(), model.Salt) != model.Password)
            {
                JscriptMsg("旧密码不正确！", "");
                return;
            }
            if (txtPassword.Text.Trim() != txtPassword1.Text.Trim())
            {
                JscriptMsg("两次密码不一致！", "");
                return;
            }
            model.Password = DESEncrypt.Encrypt(txtPassword.Text.Trim(), model.Salt);
            model.RealName = txtRealName.Text.Trim();
            model.Telephone = txtTelephone.Text.Trim();
            model.Email = txtEmail.Text.Trim();

            if (!bll.Update(model))
            {
                JscriptMsg("保存过程中发生错误！", "");
                return;
            }
            Session[WeFrameKey.SESSION_ADMIN] = null;
            JscriptMsg("密码修改成功！", "ChangePassword.aspx");
        }
    }
}